require "aio"

port = "/dev/ttyUSB0"
button = 5
led = 13

puts "Press Control+C to cancel..."

Aio::Board.new(port) do |board|
	sleep 0.1 until board.ready?
	
	board.pinMode(button, Aio::INPUT)
	board.pinMode(led, Aio::OUTPUT)
	
	state = 0
	
	loop do
		if board.digitalRead(button) == Aio::HIGH
			state = (state == 0 ? 1 : 0)
			board.digitalWrite(led, state)
			sleep 0.5
		end
	end
end
